﻿using parkMonitor.model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace parkMonitor.view.util {
	/// <summary>报警状态圆灯</summary>
	public partial class AlarmEllipse : UserControl {
		Ellipse lastShowEle = null;
		Dictionary<AlarmStatus, Ellipse> mapEle = new Dictionary<AlarmStatus, Ellipse>();
		public AlarmEllipse() {
			InitializeComponent();
			mapEle[AlarmStatus.Normal] = stuNormal;
			mapEle[AlarmStatus.Offline] = stuOffline;
			mapEle[AlarmStatus.Reset] = stuReset;
			mapEle[AlarmStatus.Warning] = stuWarn;
			mapEle[AlarmStatus.Error] = stuError;
		}

		//name列宽
		public static readonly DependencyProperty AlarmStatusPro = DependencyProperty.Register("AlarmStatus", typeof(AlarmStatus), typeof(AlarmEllipse), new FrameworkPropertyMetadata(AlarmStatus.None, new PropertyChangedCallback(_OnAlarmStatusChanged)));
		public AlarmStatus AlarmStatus {
			get { return (AlarmStatus)GetValue(AlarmStatusPro); }
			set { SetCurrentValue(AlarmStatusPro, value); }
		}

		private static void _OnAlarmStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
			AlarmEllipse ele = d as AlarmEllipse;
			if(ele == null) {
				return;
			}

			AlarmStatus? status = e.NewValue as AlarmStatus?;
			if(status == null) {
				return;
			}
			
			ele.switchedAlarmStatus((AlarmStatus)status);
		}

		private void switchedAlarmStatus(AlarmStatus newStatus) {
			if(lastShowEle != null) {
				lastShowEle.Visibility = Visibility.Collapsed;
			}

			if(mapEle.ContainsKey(newStatus)) {
				lastShowEle = mapEle[newStatus];
				lastShowEle.Visibility = Visibility.Visible;
			} else {
				lastShowEle = null;
			}

		}

	}
}
